package com.qing.study.controller;

import com.qing.study.comm.Result;
import com.qing.study.service.SendMailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

@RestController
@Api(tags = "发送邮件服务")
public class SendMailController {

    @Autowired
    private SendMailService sendMailService;


    @ApiOperation("发送普通文件邮件")
    @GetMapping("sendSimplenessMail")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "recipients", value = "收件人邮箱", dataType = "String", required = true),
            @ApiImplicitParam(name = "subject", value = "主题", dataType = "String", required = true),
            @ApiImplicitParam(name = "content", value = "内容", dataType = "String", required = true)})
    public Result sendSimplenessMail(String recipients, String subject, String content){
        return sendMailService.sendMail(recipients, subject, content);
    }

    @ApiOperation("发送带附件邮件")
    @GetMapping("sendFileMail")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "recipients", value = "收件人邮箱", dataType = "String", required = true),
            @ApiImplicitParam(name = "subject", value = "主题", dataType = "String", required = true),
            @ApiImplicitParam(name = "content", value = "内容", dataType = "String", required = true),
            @ApiImplicitParam(name = "filePath", value = "附件路径", dataType = "String", required = true)})
    public Result sendFileMail(String recipients, String subject, String content,String filePath) throws MessagingException {
        return sendMailService.sendMail(recipients, subject, content,filePath);
    }
}
